By Steve Ewing

January 1, 0001

Can I copy Kyle’s map and post to bsky as a reply?

First the map.

library(tidycensus)
library(tigris)
## To enable caching of data, set `options(tigris_use_cache = TRUE)`
## in your R script or .Rprofile.
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.1     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.1
## ✔ purrr     1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
options(tigris_use_cache = TRUE)

# Grab the data
us_wfh <- get_acs(
  geography = "puma",
  variables = "DP03_0024P",
  year = 2023,
  survey = "acs1",
  geometry = TRUE
) 
## Getting data from the 2023 1-year ACS
## The 1-year ACS provides data for geographies with populations of 65,000 and greater.
## Warning: • You have not set a Census API key. Users without a key are limited to 500
## queries per day and may experience performance limitations.
## ℹ For best results, get a Census API key at
## http://api.census.gov/data/key_signup.html and then supply the key to the
## `census_api_key()` function to use it throughout your tidycensus session.
## This warning is displayed once per session.
## Using the ACS Data Profile
# Interactive map with mapgl
library(mapgl)
## Warning: package 'mapgl' was built under R version 4.4.2
# Format the popup
popup_content <- glue::glue(
  "<strong>{us_wfh$NAME}</strong><br>",
  "% working from home: {us_wfh$estimate}"
)

us_wfh$popup <- popup_content

# Build the interactive map
wfh_map <- mapboxgl(
  style = mapbox_style("light"), 
  center = c(-98.5795, 39.8283), 
  zoom = 3
) %>%
  add_fill_layer(
    id = "puma_wfh",
    source = us_wfh,
    fill_color = interpolate(
      column = "estimate",
      values = c(1.4, 9.4, 14.9, 22.2, 36.5),
      stops = viridisLite::plasma(5),
      na_color = "lightgrey"
    ),
    fill_opacity = 0.7,
    popup = "popup", 
    hover_options = list(
      fill_color = "cyan",
      fill_opacity = 1
    )
  ) %>%
  add_legend(
    "% working from home by PUMA, 2023 1-year ACS",
    values = c("1.4%", "9.4%", "14.9%", "22.2%", "36.5%"),
    colors = viridisLite::plasma(5)
  )

wfh_map

Map works, can confirm. Now to save it then try to post it as a reply

# Save the map
# saveWidget(wfh_map, "C:/Users/steph/OneDrive/warp_and_weft_data/content/blog/k_walker_map/map.html", selfcontained = TRUE)

Get Kyle’s Posts

library(bskyr)
## Warning: package 'bskyr' was built under R version 4.4.2
kw_posts <- bs_get_author_feed("kylewalker.bsky.social")
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## • `post.record.facets.features.$type` ->
##   `post.record.facets.features.$type...21`
## • `post.record.facets.features.uri` -> `post.record.facets.features.uri...22`
## • `post.record.facets.index.byteEnd` -> `post.record.facets.index.byteEnd...23`
## • `post.record.facets.index.byteStart` ->
##   `post.record.facets.index.byteStart...24`
## • `post.record.facets.features.$type` ->
##   `post.record.facets.features.$type...25`
## • `post.record.facets.features.uri` -> `post.record.facets.features.uri...26`
## • `post.record.facets.index.byteEnd` -> `post.record.facets.index.byteEnd...27`
## • `post.record.facets.index.byteStart` ->
##   `post.record.facets.index.byteStart...28`
## • `reply.root.record.facets.features.$type` ->
##   `reply.root.record.facets.features.$type...67`
## • `reply.root.record.facets.features.tag` ->
##   `reply.root.record.facets.features.tag...68`
## • `reply.root.record.facets.index.byteEnd` ->
##   `reply.root.record.facets.index.byteEnd...69`
## • `reply.root.record.facets.index.byteStart` ->
##   `reply.root.record.facets.index.byteStart...70`
## • `reply.root.record.facets.features.$type` ->
##   `reply.root.record.facets.features.$type...71`
## • `reply.root.record.facets.features.tag` ->
##   `reply.root.record.facets.features.tag...72`
## • `reply.root.record.facets.index.byteEnd` ->
##   `reply.root.record.facets.index.byteEnd...73`
## • `reply.root.record.facets.index.byteStart` ->
##   `reply.root.record.facets.index.byteStart...74`
## • `reply.root.record.facets.features.$type` ->
##   `reply.root.record.facets.features.$type...75`
## • `reply.root.record.facets.features.uri` ->
##   `reply.root.record.facets.features.uri...76`
## • `reply.root.record.facets.index.byteEnd` ->
##   `reply.root.record.facets.index.byteEnd...77`
## • `reply.root.record.facets.index.byteStart` ->
##   `reply.root.record.facets.index.byteStart...78`
## • `reply.root.record.facets.features.$type` ->
##   `reply.root.record.facets.features.$type...79`
## • `reply.root.record.facets.features.uri` ->
##   `reply.root.record.facets.features.uri...80`
## • `reply.root.record.facets.index.byteEnd` ->
##   `reply.root.record.facets.index.byteEnd...81`
## • `reply.root.record.facets.index.byteStart` ->
##   `reply.root.record.facets.index.byteStart...82`
## • `reply.parent.record.facets.features.$type` ->
##   `reply.parent.record.facets.features.$type...118`
## • `reply.parent.record.facets.features.tag` ->
##   `reply.parent.record.facets.features.tag...119`
## • `reply.parent.record.facets.index.byteEnd` ->
##   `reply.parent.record.facets.index.byteEnd...120`
## • `reply.parent.record.facets.index.byteStart` ->
##   `reply.parent.record.facets.index.byteStart...121`
## • `reply.parent.record.facets.features.$type` ->
##   `reply.parent.record.facets.features.$type...122`
## • `reply.parent.record.facets.features.tag` ->
##   `reply.parent.record.facets.features.tag...123`
## • `reply.parent.record.facets.index.byteEnd` ->
##   `reply.parent.record.facets.index.byteEnd...124`
## • `reply.parent.record.facets.index.byteStart` ->
##   `reply.parent.record.facets.index.byteStart...125`
## • `reply.parent.record.facets.features.$type` ->
##   `reply.parent.record.facets.features.$type...126`
## • `reply.parent.record.facets.features.uri` ->
##   `reply.parent.record.facets.features.uri...127`
## • `reply.parent.record.facets.index.byteEnd` ->
##   `reply.parent.record.facets.index.byteEnd...128`
## • `reply.parent.record.facets.index.byteStart` ->
##   `reply.parent.record.facets.index.byteStart...129`
## • `reply.parent.record.facets.features.$type` ->
##   `reply.parent.record.facets.features.$type...130`
## • `reply.parent.record.facets.features.uri` ->
##   `reply.parent.record.facets.features.uri...131`
## • `reply.parent.record.facets.index.byteEnd` ->
##   `reply.parent.record.facets.index.byteEnd...132`
## • `reply.parent.record.facets.index.byteStart` ->
##   `reply.parent.record.facets.index.byteStart...133`

Now to post the map as a reply to Kyle’s latest post

# Get the latest post
latest_post <- kw_posts[1,]

# Post the map as a reply
# bs_post(
#   text = "Nice map, code works, thanks for sharing!",
#   reply = latest_post$reply_root.uri[1]
# )
Posted on:
January 1, 0001
Length:
4 minute read, 809 words
See Also: